<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  String user = (String) session.getAttribute("user");
  if (user == null) {
    response.sendRedirect("index.jsp");
    return;
  }
%>
<html>
<head>
  <title>居民首页</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    :root {
      --primary: #1E40AF;
      --primary-light: #3B82F6;
      --success: #059669;
      --warning: #D97706;
      --danger: #DC2626;
      --light: #F3F4F6;
      --white: #FFFFFF;
      --text-dark: #1F2937;
      --text-gray: #6B7280;
      --shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
      --shadow-hover: 0 10px 15px rgba(0, 0, 0, 0.1);
      --radius: 12px;
      --transition: all 0.3s ease;
    }

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      text-decoration: none;
    }

    body {
      font-family: 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
      background-color: var(--light);
      color: var(--text-dark);
      min-height: 100vh;
    }

    /* 顶部导航 */
    .header {
      background-color: var(--white);
      padding: 1rem 5rem;
      box-shadow: var(--shadow);
      position: sticky;
      top: 0;
      z-index: 100;
    }

    .header-content {
      max-width: 1400px;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .logo {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .logo-img {
      width: 48px;
      height: 48px;
      background-color: var(--primary);
      border-radius: 8px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: white;
      font-size: 1.5rem;
    }

    .logo-text {
      font-size: 1.4rem;
      font-weight: 600;
      color: var(--primary);
    }

    .user-menu {
      display: flex;
      align-items: center;
      gap: 2rem;
    }

    .greeting {
      font-size: 1rem;
      color: var(--text-dark);
    }

    .logout-btn {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 16px;
      background-color: transparent;
      border: 1px solid var(--primary);
      color: var(--primary);
      border-radius: 6px;
      font-weight: 500;
      cursor: pointer;
      transition: var(--transition);
    }

    .logout-btn:hover {
      background-color: var(--primary);
      color: white;
    }

    /* 主内容区 */
    .main {
      max-width: 1400px;
      margin: 3rem auto;
      padding: 0 5rem;
    }

    .page-title {
      text-align: center;
      margin-bottom: 3rem;
    }

    .page-title h1 {
      font-size: 2.2rem;
      margin-bottom: 0.8rem;
      color: var(--text-dark);
    }

    .page-title p {
      font-size: 1.1rem;
      color: var(--text-gray);
      max-width: 800px;
      margin: 0 auto;
    }

    /* 功能卡片容器 */
    .features {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 2.5rem;
    }

    /* 功能卡片 */
    .feature-card {
      background-color: var(--white);
      border-radius: var(--radius);
      padding: 2.5rem 2rem;
      box-shadow: var(--shadow);
      transition: var(--transition);
      display: flex;
      flex-direction: column;
      height: 100%;
      position: relative;
      overflow: hidden;
    }

    .feature-card::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 4px;
    }

    .feature-card.history::before {
      background-color: var(--success);
    }

    .feature-card.report::before {
      background-color: var(--danger);
    }

    .feature-card.alerts::before {
      background-color: var(--warning);
    }

    .feature-card:hover {
      transform: translateY(-8px);
      box-shadow: var(--shadow-hover);
    }

    /* 卡片图标 */
    .card-icon {
      width: 70px;
      height: 70px;
      border-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-bottom: 1.5rem;
      font-size: 2rem;
    }

    .history .card-icon {
      background-color: rgba(5, 150, 105, 0.1);
      color: var(--success);
    }

    .report .card-icon {
      background-color: rgba(220, 38, 38, 0.1);
      color: var(--danger);
    }

    .alerts .card-icon {
      background-color: rgba(217, 119, 6, 0.1);
      color: var(--warning);
    }

    /* 卡片内容 */
    .card-title {
      font-size: 1.5rem;
      font-weight: 600;
      margin-bottom: 1rem;
      color: var(--text-dark);
    }

    .card-desc {
      color: var(--text-gray);
      line-height: 1.7;
      margin-bottom: 2rem;
      flex: 1;
    }

    /* 卡片按钮 */
    .card-action {
      display: inline-flex;
      align-items: center;
      gap: 10px;
      color: var(--primary);
      font-weight: 500;
      margin-top: auto;
      transition: var(--transition);
    }

    .card-action i {
      transition: transform 0.3s ease;
    }

    .feature-card:hover .card-action i {
      transform: translateX(5px);
    }

    /* 页脚 */
    .footer {
      background-color: var(--white);
      padding: 2rem 5rem;
      margin-top: 5rem;
      border-top: 1px solid #E5E7EB;
      text-align: center;
      color: var(--text-gray);
      font-size: 0.95rem;
    }
  </style>
  <!-- 引入Font Awesome图标 -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
</head>
<body>
<!-- 顶部导航 -->
<header class="header">
  <div class="header-content">
    <div class="logo">
      <div class="logo-img">
        <i class="fas fa-shield-alt"></i>
      </div>
      <div class="logo-text">社区应急服务平台</div>
    </div>

    <div class="user-menu">
      <div class="greeting">欢迎您，居民朋友</div>
      <button class="logout-btn" onclick="window.location.href='index.jsp'">
        <i class="fas fa-sign-out-alt"></i>
        <span>退出登录</span>
      </button>
    </div>
  </div>
</header>

<!-- 主内容区 -->
<main class="main">
  <div class="page-title">
    <h1>应急服务功能中心</h1>
    <p>为您提供全方位的灾害应对服务，包括灾情查询、实时上报和预警信息获取，助力社区安全防护</p>
  </div>

  <div class="features">
    <!-- 历史灾情查询 -->
    <a href="historyDisaster.jsp" class="feature-card history">
      <div class="card-icon">
        <i class="fas fa-history"></i>
      </div>
      <h3 class="card-title">历史灾情查询</h3>
      <p class="card-desc">
        查阅本地区历史灾害记录，包括灾害类型、发生时间、影响范围、处置结果等详细信息，为防灾减灾提供参考依据。
      </p>
      <div class="card-action">
        <span>进入查询</span>
        <i class="fas fa-arrow-right"></i>
      </div>
    </a>

    <!-- 灾害情况上报 -->
    <a href="reportDisaster.jsp" class="feature-card report">
      <div class="card-icon">
        <i class="fas fa-exclamation-circle"></i>
      </div>
      <h3 class="card-title">灾害情况上报</h3>
      <p class="card-desc">
        发现险情或灾害时，可通过此功能快速上报详细信息，包括灾害类型、发生地点、现场情况等，以便相关部门及时处置。
      </p>
      <div class="card-action">
        <span>立即上报</span>
        <i class="fas fa-arrow-right"></i>
      </div>
    </a>

    <!-- 预警信息查看 -->
    <a href="viewAlerts" class="feature-card alerts">
      <div class="card-icon">
        <i class="fas fa-bell"></i>
      </div>
      <h3 class="card-title">预警信息查看</h3>
      <p class="card-desc">
        获取最新的灾害预警通知，包括气象灾害、地质灾害等预警信息，提前做好防范准备，保障生命财产安全。
      </p>
      <div class="card-action">
        <span>查看预警</span>
        <i class="fas fa-arrow-right"></i>
      </div>
    </a>
  </div>
</main>

<!-- 页脚 -->
<footer class="footer">
  <p>应急服务系统 © 2025 | 技术支持</p>
</footer>

<!-- 消息提示脚本 -->
<script>
  // 显示成功提示
  function showSuccessToast(message) {
    const existingToast = document.querySelector('.success-toast');
    if (existingToast) existingToast.remove();

    const toast = document.createElement('div');
    toast.className = 'success-toast';
    toast.innerHTML = `
        <i class="fas fa-check-circle"></i>
        <span>${message}</span>
      `;
    document.body.appendChild(toast);

    setTimeout(() => toast.style.transform = 'translateX(0)', 100);
    setTimeout(() => {
      toast.style.transform = 'translateX(calc(100% + 30px))';
      setTimeout(() => toast.remove(), 500);
    }, 3000);
  }

  // 显示错误提示
  function showErrorToast(message) {
    const existingToast = document.querySelector('.error-toast');
    if (existingToast) existingToast.remove();

    const toast = document.createElement('div');
    toast.className = 'error-toast';
    toast.innerHTML = `
        <i class="fas fa-exclamation-circle"></i>
        <span>${message}</span>
      `;
    document.body.appendChild(toast);

    setTimeout(() => toast.style.transform = 'translateX(0)', 100);
    setTimeout(() => {
      toast.style.transform = 'translateX(calc(100% + 30px))';
      setTimeout(() => toast.remove(), 500);
    }, 3000);
  }
</script>

<style>
  /* 提示框样式 */
  .success-toast, .error-toast {
    position: fixed;
    top: 30px;
    right: 30px;
    padding: 16px 25px;
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 9999;
    transform: translateX(calc(100% + 30px));
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 1rem;
    min-width: 300px;
  }

  .success-toast {
    background-color: var(--success);
    color: white;
  }

  .error-toast {
    background-color: var(--danger);
    color: white;
  }
</style>

<%
  // 从session中获取消息并显示
  Object successMsg = session.getAttribute("message");
  Object errorMsg = session.getAttribute("errorMessage");

  if (successMsg != null) {
%>
<script>
  showSuccessToast("<%= successMsg.toString() %>");
</script>
<%
    session.removeAttribute("message");
  }

  if (errorMsg != null) {
%>
<script>
  showErrorToast("<%= errorMsg.toString() %>");
</script>
<%
    session.removeAttribute("errorMessage");
  }
%>
</body>
</html>